#include "net8814zwavewidget.h"
#include <QChart>
#include <QLineSeries>
#include <QList>
#include <QPointF>

Net8814ZWaveWidget::Net8814ZWaveWidget(QWidget *parent)
    : ContentWidget(parent) {
    m_pChart = new QChart;
    //![1]
    m_pLineSeries = new QLineSeries;
    //![1]

    //![2]
    m_pLineSeries->append(0, 6);
    m_pLineSeries->append(2, 4);
    m_pLineSeries->append(3, 8);
    m_pLineSeries->append(7, 4);
    m_pLineSeries->append(10, 5);
    *m_pLineSeries << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
    //![2]

    //series->setUseOpenGL(true);  // 开启OPENGL

    //![3]

    m_pChart->legend()->hide();
    m_pChart->addSeries(m_pLineSeries);
    m_pChart->createDefaultAxes();
    m_pChart->setTitle("Simple Line Chart");
    //![3]

    //![4]
    createDefaultChartView(m_pChart);
    //![4]
    //!
    connect((MainWindow*)MainWindow::instance(),&MainWindow::SendInformation,this,&Net8814ZWaveWidget::ReceiveMessage);
}

void Net8814ZWaveWidget::ReceiveMessage(float64* pData){
    //qDebug() << "Receive a new message!";
    QList<QPointF> *pDatas = new QList<QPointF>();
    for(int i = 0;i < 2000;i++){
        pDatas->append(QPointF(i,pData[i]));
    }
    m_pChart->removeAllSeries();
    //m_pLineSeries->clear();
    QLineSeries *pLineSeries = new QLineSeries;
    pLineSeries->clear();
    pLineSeries->append(*pDatas);
    m_pChart->addSeries(pLineSeries);
}
